﻿using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Linq;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class TAV11
    {


        public TAV11()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VKSLEIST();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                AMVKEY = "";
            }
            else
            {
                filter = "KSLSMNRKRS='" + TMV.KSLSMNRKRS + "' AND KSLSMLFDNR='" + TMV.KSLSMLFDNR + "' AND KSLSMPOS='" + TMV.KSLSMPOS + "'";
                sort = "KSLMDAT ASC,KSLMZTV ASC";
                rows = TBMain.Copy().Select(filter);
                int cnt = rows.Length - 1;
                AMVKEY = rows[0]["KSLSMNRKRS"].ToString() + rows[0]["KSLSMLFDNR"].ToString() + rows[0]["KSLSMPOS"].ToString()
                    + rows[0]["KSLMDAT"].ToString() + rows[0]["KSLMZTV"].ToString() + ","
                    + rows[cnt]["KSLMDAT"].ToString() + rows[cnt]["KSLMZTV"].ToString();
            }
        }
        public override void OnEXAUFChg(string vlaue)
        {
            if (EXAUF.Trim().Length < 14)
            {
                TBMain.Clear();
                return;
            }
            dwData = TBMain.NewRow();
            dwData["KSLMANDANT"] = app.Mandant;
            dwData["KSLAUFKRS"] = EXAUF.Substring(0, 2);
            dwData["KSLAUFLFD"] = EXAUF.Substring(2, 6);
            dwData["KSLAUFPOS"] = EXAUF.Substring(8, 3);
            dwData["KSLAFOLGE"] = EXAUF.Substring(11, 3);
            SResult = TMV.QueryKSLEIST(dwData, 6);
            MergeData(SResult, false);
            base.OnEXAUFChg(vlaue);
        }
    }
}
